<?xml version="1.0"?>

<st-source>
<time-stamp>From VisualWorks® NonCommercial, 7.6 of March 3, 2008 on April 14, 2009 at 3:37:38 pm</time-stamp>


<class>
<name>Retailer</name>
<environment>SupplyChain</environment>
<super>Core.Object</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>location number sellPolicy inventory ccs name </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category></category>
<attributes>
<package>SupplyChain</package>
</attributes>
</class>

<!-- -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -   -->


<methods>
<class-id>SupplyChain.Retailer class</class-id> <category>instance creation</category>

<body package="SupplyChain" selector="new">new
	"Answer a newly created and initialized instance."

	^super new initialize</body>
</methods>

<!-- -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -   -->


<comment>
<class-id>SupplyChain.Retailer</class-id>
<body>A specific outlet store or other point-of-sale location.

Instance Variables:
	location	&lt;String&gt;	The location of the store
	number	&lt;Integer&gt;	The store's ID number
	sellPolicy	&lt;Policy&gt;	The policy this store sells items with

</body>
</comment>

<methods>
<class-id>SupplyChain.Retailer</class-id> <category>changing</category>

<body package="SupplyChain" selector="setPolicy:">setPolicy: aPolicy
	"Sets the sellPolicy of the store"

	self sellPolicy: aPolicy</body>

<body package="SupplyChain" selector="shipmentArrived:">shipmentArrived: anInvoiceList
	"Add to the list of items"

	anInvoiceList do:[ :i| i itemList do: [ :item |
		(inventory hasItem: item)
			ifFalse: [ inventory addItem: (Item named: (item name) sku: (item sku)) ].
			
			inventory restockItem: item.].].</body>
</methods>

<methods>
<class-id>SupplyChain.Retailer</class-id> <category>accessing</category>

<body package="SupplyChain" selector="ccs">ccs
	^ccs</body>

<body package="SupplyChain" selector="ccs:">ccs: anObject
	ccs := anObject</body>

<body package="SupplyChain" selector="hasItem:">hasItem: anItem
	"Tests if this retailer's inventory contains an item."
	
	^inventory items includes: anItem.</body>

<body package="SupplyChain" selector="inventory">inventory
	^inventory</body>

<body package="SupplyChain" selector="inventory:">inventory: anObject
	inventory := anObject</body>

<body package="SupplyChain" selector="location">location
	^location</body>

<body package="SupplyChain" selector="location:">location: anObject
	location := anObject</body>

<body package="SupplyChain" selector="name">name
	^name.</body>

<body package="SupplyChain" selector="name:">name: anObject
	name := anObject</body>

<body package="SupplyChain" selector="number">number
	^number</body>

<body package="SupplyChain" selector="number:">number: anObject
	number := anObject</body>

<body package="SupplyChain" selector="orderedItemsList">orderedItemsList
	"Gets a list of ordered items for this Retailer"

	^inventory items.</body>

<body package="SupplyChain" selector="sellPolicy">sellPolicy
	^sellPolicy</body>

<body package="SupplyChain" selector="sellPolicy:">sellPolicy: anObject
	sellPolicy := anObject.
	sellPolicy inventory: inventory.</body>
</methods>

<methods>
<class-id>SupplyChain.Retailer</class-id> <category>printing</category>

<body package="SupplyChain" selector="printString">printString
	^(name,' ', location, ' ', number).</body>
</methods>

<methods>
<class-id>SupplyChain.Retailer</class-id> <category>controlling</category>

<body package="SupplyChain" selector="reorder:">reorder: anItem
	"Reorders an item from the CCS"
	
	| order |
	
	order := Order new.
	order add: anItem.
	ccs handleOrder: order</body>

<body package="SupplyChain" selector="sellItem:">sellItem: anItem
	"Attempts to sell an item.
	Returns the item if the item is sold, nil if the item was not found."
	
	| item |
	
	^(self hasItem: anItem)
		ifTrue:
			[item := sellPolicy determineSellItem: (anItem sku).
			item quantity: (item quantity - 1).
			item needsReorder ifTrue: [self reorder: item].
			^item]
		ifFalse:
			[^nil]</body>
</methods>

<methods>
<class-id>SupplyChain.Retailer</class-id> <category>initialize-release</category>

<body package="SupplyChain" selector="initialize">initialize
	"Initialize a newly created instance. This method must answer the receiver."

	" *** Edit the following to properly initialize instance variables ***"
	location := 'Unknown'.
	number := 0.
	sellPolicy := CheapestItemFirstPolicy new.
	inventory := Inventory new.
	" *** And replace this comment with additional initialization code *** "
	^self</body>
</methods>

</st-source>
